// SettingDlg.cpp : implementation file
//

#include "stdafx.h"
#include "VaxVoIPSample.h"
#include "SettingDlg.h"
#include "afxdialogex.h"
#include "VaxSIPUserAgent.h"
#include "Define.h"

// CSettingDlg dialog

IMPLEMENT_DYNAMIC(CSettingDlg, CPropertyPage)

CSettingDlg::CSettingDlg(CVaxSIPUserAgent* pVaxSIPUserAgent): CPropertyPage(CSettingDlg::IDD)
{
	m_psp.dwFlags &= ~PSP_HASHELP; 
	m_pVaxSIPUserAgent = pVaxSIPUserAgent;

	m_bCheckH263 = TRUE;
	m_bCheckH263P = TRUE;

	m_bCheckEchoCancellation = TRUE;

	m_bCheckG711U_LAW = TRUE;
	m_bCheckG729 = TRUE;
	m_bCheckG711A_LAW = TRUE;
	m_bCheckGSM610 = TRUE;
	m_bCheckILBC = TRUE;

	m_bCheckAGC = FALSE;
	m_bCheckMicBoost = FALSE;
	m_bCheckDontDisturb = FALSE;
	m_bCheckForceInbandDTMF = FALSE;

	m_nRadioVCSelIndex = 0;
		
	m_nCryptTunnelPort = 8891;
	m_bCryptTunnelEnable = FALSE;
				
	m_objFont.CreateFont(14, 0, 0, 0, FW_BOLD, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Verdana");                    
}

CSettingDlg::~CSettingDlg()
{

}

void CSettingDlg::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	DDX_Check(pDX, IDC_CHECK_VOICE_CODEC_GSM610, m_bCheckGSM610);
	DDX_Check(pDX, IDC_CHECK_VOICE_CODEC_ILBC, m_bCheckILBC);
	DDX_Check(pDX, IDC_CHECK_VOICE_CODEC_G729, m_bCheckG729);
	DDX_Check(pDX, IDC_CHECK_VOICE_CODEC_G711A , m_bCheckG711A_LAW);
	DDX_Check(pDX, IDC_CHECK_VOICE_CODEC_G711U, m_bCheckG711U_LAW);
	DDX_Check(pDX, IDC_CHECK_NOISE_CANCEL, m_bCheckEchoCancellation);
	DDX_Check(pDX, IDC_CHECK_AGC, m_bCheckAGC);
	DDX_Check(pDX, IDC_CHECK_MIC_BOOST, m_bCheckMicBoost);
	DDX_Check(pDX, IDC_CHECK_DO_NOT_DISTURB, m_bCheckDontDisturb);
	DDX_Check(pDX, IDC_CHECK_FORCE_INBAND_DTMF, m_bCheckForceInbandDTMF);
	DDX_Control(pDX, IDC_LIST_AUDIO_IN, m_ctrlListAudioIn);
	DDX_Control(pDX, IDC_LIST_AUDIO_OUT, m_ctrlListAudioOut);
	DDX_Control(pDX, IDC_LIST_VIDEO, m_ctrlListVideo);

	GetDlgItem(IDC_GROUP_VOICE_CODECS)->SetFont(&m_objFont);
	GetDlgItem(IDC_GROUP_VOICE_CHANGER)->SetFont(&m_objFont);
	GetDlgItem(IDC_GROUP_OTHER_SETTINGS)->SetFont(&m_objFont);

	GetDlgItem(IDC_GROUP_AUDIO_IN)->SetFont(&m_objFont);
	GetDlgItem(IDC_GROUP_AUDIO_OUT)->SetFont(&m_objFont);

	GetDlgItem(IDC_GROUP_VIDEO)->SetFont(&m_objFont);
	GetDlgItem(IDC_GROUP_VIDEO_CODECS)->SetFont(&m_objFont);

	GetDlgItem(IDC_GROUP_VIDEO_QUALITY)->SetFont(&m_objFont);
	GetDlgItem(IDC_GROUP_NETWORK_QOS)->SetFont(&m_objFont);
	GetDlgItem(IDC_GROUP_ENCRYPTION_TUNNEL)->SetFont(&m_objFont);

	DDX_Radio(pDX, IDC_RADIO_VOICE_NORMAL, m_nRadioVCSelIndex);
	DDX_Check(pDX, IDC_CHECK_VIDEO_CODEC_H263, m_bCheckH263);
	DDX_Check(pDX, IDC_CHECK_VIDEO_CODEC_H263P, m_bCheckH263P);

	DDX_Control(pDX, IDC_COMBO_VIDEO_QUALITY, m_ctrlVideoQuality);
	DDX_Control(pDX, IDC_COMBO_CALL_QOS, m_ctrlCallQoS);
	DDX_Control(pDX, IDC_COMBO_MEDIA_QOS, m_ctrlMediaQoS);

	DDX_Text(pDX, IDC_EDIT_TUNNEL_IP, m_sCryptTunnelIP);
	DDX_Text(pDX, IDC_EDIT_TUNNEL_PORT, m_nCryptTunnelPort);
	DDX_Check(pDX, IDC_CHECK_TUNNEL_ENABLE, m_bCryptTunnelEnable);
}

BEGIN_MESSAGE_MAP(CSettingDlg, CPropertyPage)
	ON_BN_CLICKED(IDC_CHECK_VOICE_CODEC_GSM610, &CSettingDlg::OnCheckCodecGsm610_CheckChanged)
	ON_BN_CLICKED(IDC_CHECK_VOICE_CODEC_ILBC, &CSettingDlg::OnCheckCodecILBC_CheckChanged)
	ON_BN_CLICKED(IDC_CHECK_VOICE_CODEC_G729, &CSettingDlg::OnCheckCodecG729_CheckChanged)
	ON_BN_CLICKED(IDC_CHECK_VOICE_CODEC_G711A, &CSettingDlg::OnCheckCodecG711A_CheckChanged)
	ON_BN_CLICKED(IDC_CHECK_VOICE_CODEC_G711U, &CSettingDlg::OnCheckCodecG711U_CheckChanged)
	ON_BN_CLICKED(IDC_RADIO_VOICE_GRANDPA, &CSettingDlg::OnRadioVCGrandpa_SelectionChanged)
	ON_BN_CLICKED(IDC_RADIO_VOICE_TEENBOY, &CSettingDlg::OnRadioVCTeen_SelectionChanged)
	ON_BN_CLICKED(IDC_RADIO_VOICE_HOUSEHOLD, &CSettingDlg::OnRadioVCHouseHold_SelectionChanged)
	ON_BN_CLICKED(IDC_RADIO_VOICE_HELIUM, &CSettingDlg::OnRadioVChelium_SelectionChanged)
	ON_BN_CLICKED(IDC_RADIO_VOICE_CHIPMUNK, &CSettingDlg::OnRadioVCChipmunk_SelectionChanged)
	ON_BN_CLICKED(IDC_CHECK_NOISE_CANCEL, &CSettingDlg::OnCheckNoiseCancel_CheckChanged)
	ON_BN_CLICKED(IDC_CHECK_AGC, &CSettingDlg::OnCheckAGC_CheckChanged)
	ON_BN_CLICKED(IDC_CHECK_MIC_BOOST, &CSettingDlg::OnCheckMICBoost_CheckChanged)
	ON_BN_CLICKED(IDC_CHECK_DO_NOT_DISTURB, &CSettingDlg::OnCheckDontDisturb_CheckChanged)
	ON_BN_CLICKED(IDC_CHECK_FORCE_INBAND_DTMF, &CSettingDlg::OnCheckForceInbandDTMF_CheckChanged)
	ON_BN_CLICKED(IDC_RADIO_VOICE_NORMAL, &CSettingDlg::OnRadioVCNormal_SelectionChanged)
	ON_LBN_SELCHANGE(IDC_LIST_AUDIO_IN, &CSettingDlg::On_SelChangeAudioIn)
	ON_LBN_SELCHANGE(IDC_LIST_AUDIO_OUT, &CSettingDlg::On_SelChangeAudioOut)
	ON_BN_CLICKED(IDC_CHECK_VIDEO_CODEC_H263, &CSettingDlg::OnBnClickedCheckVideoCodecH263)
	ON_BN_CLICKED(IDC_CHECK_VIDEO_CODEC_H263P, &CSettingDlg::OnBnClickedCheckVideoCodecH263p)
	ON_LBN_SELCHANGE(IDC_LIST_VIDEO, &CSettingDlg::On_SelChangeVideo)
	ON_CBN_SELCHANGE(IDC_COMBO_VIDEO_QUALITY, &CSettingDlg::OnSelChangeComboVideoQuality)
	ON_CBN_SELCHANGE(IDC_COMBO_CALL_QOS, &CSettingDlg::OnCbnSelchangeComboCallQos)
	ON_CBN_SELCHANGE(IDC_COMBO_MEDIA_QOS, &CSettingDlg::OnCbnSelchangeComboMediaQos)
	ON_BN_CLICKED(IDC_CHECK_TUNNEL_ENABLE, &CSettingDlg::OnBnClickedCheckTunnelEnable)
END_MESSAGE_MAP()


BOOL CSettingDlg::OnInitDialog()
{
	CPropertyPage::OnInitDialog();

	m_ctrlVideoQuality.AddString("Low");
	m_ctrlVideoQuality.AddString("Standard");
	m_ctrlVideoQuality.AddString("Medium");
	m_ctrlVideoQuality.AddString("High");
	m_ctrlVideoQuality.AddString("Max");

	m_ctrlCallQoS.SetWindowPos(NULL, 0, 0, 130, 150, SWP_NOMOVE);
	m_ctrlMediaQoS.SetWindowPos(NULL, 0, 0, 130, 150, SWP_NOMOVE);

	UpdateCallQOS();
    UpdateMediaQOS();

	m_ctrlVideoQuality.SetWindowPos(NULL, 0, 0, 180, 100, SWP_NOMOVE);
	m_ctrlVideoQuality.SetCurSel(1);
		
	return TRUE; 
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

void CSettingDlg::OnVaxInitialize()
{
	ActivateVideoQuality();

	UpdateAudioIn();
    UpdateAudioOut();
	UpdateVideo();
			
	ActivateAudioCodecs();
	ActivateVideoCodecs();
		
	ActivateOtherSettings();
	ActivateVoiceChanger();

	ActivateQoS();
	ActivateEncryptionTunnel();
}

void CSettingDlg::OnVaxUnInitialize()
{
		
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

void CSettingDlg::UpdateAudioIn()
{
	m_ctrlListAudioIn.ResetContent();

	int nDeviceId;
    CString sDeviceName;

	m_ctrlListAudioIn.InsertString(0,"Default Device");
	m_ctrlListAudioIn.SetItemData(0, -1);

    for(int nDeviceIndex = 0; nDeviceIndex < m_pVaxSIPUserAgent->GetAudioInDevTotal(); nDeviceIndex++)
    {
        nDeviceId = m_pVaxSIPUserAgent->GetAudioInDevId(nDeviceIndex);
        sDeviceName = m_pVaxSIPUserAgent->GetAudioInDevName(nDeviceIndex);

		int nIndexInsertedItem = m_ctrlListAudioIn.AddString(sDeviceName);

		m_ctrlListAudioIn.SetItemData(nIndexInsertedItem, nDeviceId);
    }

	m_ctrlListAudioIn.SetCurSel(0);
 
	int nIndex = m_ctrlListAudioIn.GetTopIndex();
	nDeviceId = m_ctrlListAudioIn.GetItemData(nIndex);

    m_pVaxSIPUserAgent->SetActiveAudioInDevice(nDeviceId);
}

void CSettingDlg::UpdateAudioOut()
{
	m_ctrlListAudioOut.ResetContent();

	int nDeviceId;
    CString sDeviceName;

	int nTest = m_ctrlListAudioOut.InsertString(0, "Default Device");
	m_ctrlListAudioOut.SetItemData(0, -1);

    for(int nDeviceIndex = 0; nDeviceIndex < m_pVaxSIPUserAgent->GetAudioOutDevTotal(); nDeviceIndex++)
    {
        nDeviceId = m_pVaxSIPUserAgent->GetAudioOutDevId(nDeviceIndex);
        sDeviceName = m_pVaxSIPUserAgent->GetAudioOutDevName(nDeviceIndex);

		int nIndexInsertedItem = m_ctrlListAudioOut.AddString(sDeviceName);
		m_ctrlListAudioOut.SetItemData(nIndexInsertedItem, nDeviceId);
    }

	m_ctrlListAudioOut.SetCurSel(0);
 
	int nIndex = m_ctrlListAudioOut.GetTopIndex();
	nDeviceId = m_ctrlListAudioOut.GetItemData(nIndex);
    m_pVaxSIPUserAgent->SetActiveAudioOutDevice(nDeviceId);
}

void CSettingDlg::UpdateVideo()
{
	m_ctrlListVideo.ResetContent();

	if(m_pVaxSIPUserAgent->GetVideoDevTotal() == 0)
		return;
    
	for(int nDeviceIndex = 0; nDeviceIndex < m_pVaxSIPUserAgent->GetVideoDevTotal(); nDeviceIndex++)
    {
        CString sDeviceName = m_pVaxSIPUserAgent->GetVideoDevName(nDeviceIndex);
		
		int nIndexInsertedItem = m_ctrlListVideo.AddString(sDeviceName);
		m_ctrlListVideo.SetItemData(nIndexInsertedItem, nDeviceIndex);
    }

	m_ctrlListVideo.SetCurSel(0);
		
	int nDeviceId = m_ctrlListVideo.GetItemData(0);
    m_pVaxSIPUserAgent->SetActiveVideoDevice(nDeviceId);
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

void CSettingDlg::UpdateCallQOS()
{
	m_ctrlCallQoS.ResetContent();

    m_ctrlCallQoS.InsertString(0, "Disable");
	m_ctrlCallQoS.SetItemData(0, -1);

	m_ctrlCallQoS.InsertString(1, "Lowest");
	m_ctrlCallQoS.SetItemData(1, QOS_PRIORITY_LOWEST);

	m_ctrlCallQoS.InsertString(2, "Lower");
	m_ctrlCallQoS.SetItemData(2, QOS_PRIORITY_LOWER);

	m_ctrlCallQoS.InsertString(3, "Low");
	m_ctrlCallQoS.SetItemData(3, QOS_PRIORITY_LOW);

	m_ctrlCallQoS.InsertString(4, "High");
	m_ctrlCallQoS.SetItemData(4, QOS_PRIORITY_HIGH);

	m_ctrlCallQoS.InsertString(5, "Higher");
	m_ctrlCallQoS.SetItemData(5, QOS_PRIORITY_HIGHER);

	m_ctrlCallQoS.InsertString(6, "Highest");
	m_ctrlCallQoS.SetItemData(6, QOS_PRIORITY_HIGHEST);

	m_ctrlCallQoS.SetCurSel(0);
}

void CSettingDlg::UpdateMediaQOS()
{
	m_ctrlMediaQoS.ResetContent();

    m_ctrlMediaQoS.InsertString(0, "Disable");
	m_ctrlMediaQoS.SetItemData(0, -1);

	m_ctrlMediaQoS.InsertString(1, "Lowest");
	m_ctrlMediaQoS.SetItemData(1, QOS_PRIORITY_LOWEST);

	m_ctrlMediaQoS.InsertString(2, "Lower");
	m_ctrlMediaQoS.SetItemData(2, QOS_PRIORITY_LOWER);

	m_ctrlMediaQoS.InsertString(3, "Low");
	m_ctrlMediaQoS.SetItemData(3, QOS_PRIORITY_LOW);

	m_ctrlMediaQoS.InsertString(4, "High");
	m_ctrlMediaQoS.SetItemData(4, QOS_PRIORITY_HIGH);

	m_ctrlMediaQoS.InsertString(5, "Higher");
	m_ctrlMediaQoS.SetItemData(5, QOS_PRIORITY_HIGHER);

	m_ctrlMediaQoS.InsertString(6, "Highest");
	m_ctrlMediaQoS.SetItemData(6, QOS_PRIORITY_HIGHEST);

	m_ctrlMediaQoS.SetCurSel(0);
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

void CSettingDlg::OnSuccessToConnect(int nLineNo, LPCTSTR sToRTPIP, int nToRTPPort)
{
	m_bCheckMicBoost = m_pVaxSIPUserAgent->IsMicBoostEnable();
	UpdateData(FALSE);
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

void CSettingDlg::OnCheckCodecGsm610_CheckChanged()
{
   /****Codec No 0 represents GSM 6.10 *****/

	UpdateData(TRUE);

	if(m_bCheckGSM610)
		m_pVaxSIPUserAgent->SelectVoiceCodec(VAX_CODEC_GSM610);
	else
		m_pVaxSIPUserAgent->DeselectVoiceCodec(VAX_CODEC_GSM610);
}

void CSettingDlg::OnCheckCodecILBC_CheckChanged()
{
    /****Codec No 1 represents iLBC *****/

	UpdateData(TRUE);

    if(m_bCheckILBC)
        m_pVaxSIPUserAgent->SelectVoiceCodec(VAX_CODEC_ILBC);
    else
        m_pVaxSIPUserAgent->DeselectVoiceCodec(VAX_CODEC_ILBC);
}

void CSettingDlg::OnCheckCodecG729_CheckChanged()
{
    /****Codec No 4 represents G729 *****/

	UpdateData(TRUE);

	if(m_bCheckG729)
        m_pVaxSIPUserAgent->SelectVoiceCodec(VAX_CODEC_G729);
    else
        m_pVaxSIPUserAgent->DeselectVoiceCodec(VAX_CODEC_G729);
}

void CSettingDlg::OnCheckCodecG711A_CheckChanged()
{
    /****Codec No 2 represents G711 A-LAW *****/

	UpdateData(TRUE);

    if(m_bCheckG711A_LAW)
        m_pVaxSIPUserAgent->SelectVoiceCodec(VAX_CODEC_G711A);
    else
        m_pVaxSIPUserAgent->DeselectVoiceCodec(VAX_CODEC_G711A); 
}

void CSettingDlg::OnCheckCodecG711U_CheckChanged()
{
   /****Codec No 3 represents G711 U-LAW *****/

	UpdateData(TRUE);

	if(m_bCheckG711U_LAW)
        m_pVaxSIPUserAgent->SelectVoiceCodec(VAX_CODEC_G711U);
    else
        m_pVaxSIPUserAgent->DeselectVoiceCodec(VAX_CODEC_G711U);	
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

void CSettingDlg::OnRadioVCNormal_SelectionChanged()
{
	m_pVaxSIPUserAgent->VoiceChanger(-1);
}

void CSettingDlg::OnRadioVCGrandpa_SelectionChanged()
{
	m_pVaxSIPUserAgent->VoiceChanger(4);
}

void CSettingDlg::OnRadioVCTeen_SelectionChanged()
{
	m_pVaxSIPUserAgent->VoiceChanger(8);
}

void CSettingDlg::OnRadioVCHouseHold_SelectionChanged()
{
	m_pVaxSIPUserAgent->VoiceChanger(12);
}

void CSettingDlg::OnRadioVChelium_SelectionChanged()
{
	m_pVaxSIPUserAgent->VoiceChanger(16);
}

void CSettingDlg::OnRadioVCChipmunk_SelectionChanged()
{
	m_pVaxSIPUserAgent->VoiceChanger(20);
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

void CSettingDlg::OnCheckNoiseCancel_CheckChanged()
{
	UpdateData(TRUE);

	if(m_bCheckEchoCancellation)
		m_pVaxSIPUserAgent->EnableEchoNoiseCancellation();
	else
		m_pVaxSIPUserAgent->DisableEchoNoiseCancellation();
}

void CSettingDlg::OnCheckAGC_CheckChanged()
{
	UpdateData(TRUE);

	if(m_bCheckAGC)
        m_pVaxSIPUserAgent->EnableAGC(8000);
    else
        m_pVaxSIPUserAgent->DisableAGC();  
}

void CSettingDlg::OnCheckMICBoost_CheckChanged()
{
	UpdateData(TRUE);

    if(m_bCheckMicBoost)
        m_pVaxSIPUserAgent->EnableMicBoost();
    else
       m_pVaxSIPUserAgent->DisableMicBoost();
}

void CSettingDlg::OnCheckDontDisturb_CheckChanged()
{
	UpdateData(TRUE);

    if(m_bCheckDontDisturb)
        m_pVaxSIPUserAgent->EnableDonotDisturb();
    else
        m_pVaxSIPUserAgent->DisableDonotDisturb();
}

void CSettingDlg::OnCheckForceInbandDTMF_CheckChanged()
{
	UpdateData(TRUE);

    int nTotalLine = m_pVaxSIPUserAgent->GetTotalLine();

    for(int nLineCount = 0; nLineCount < nTotalLine; nLineCount++)
    {
		if(m_bCheckForceInbandDTMF)
            m_pVaxSIPUserAgent->EnableForceInbandDTMF(nLineCount);
        else
            m_pVaxSIPUserAgent->DisableForceInbandDTMF(nLineCount);
    }
}

////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

BOOL CSettingDlg::OnApply()
{
	return FALSE;
	//return  CPropertyPage::OnApply();
}

////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

void CSettingDlg::On_SelChangeAudioIn()
{
	int nSelIndex = m_ctrlListAudioIn.GetCurSel();
	int nDeviceId = m_ctrlListAudioIn.GetItemData(nSelIndex);

	m_pVaxSIPUserAgent->SetActiveAudioInDevice(nDeviceId);
}

void CSettingDlg::On_SelChangeAudioOut()
{
	int nSelIndex = m_ctrlListAudioOut.GetCurSel();
	int nDeviceId = m_ctrlListAudioOut.GetItemData(nSelIndex);
 
	m_pVaxSIPUserAgent->SetActiveAudioOutDevice(nDeviceId);
}

void CSettingDlg::On_SelChangeVideo()
{
	int nSelIndex = m_ctrlListVideo.GetCurSel();
	if(nSelIndex == -1) return;

	int nDeviceId = m_ctrlListVideo.GetItemData(nSelIndex);
	m_pVaxSIPUserAgent->SetActiveVideoDevice(nDeviceId);
}

////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

void CSettingDlg::OnBnClickedCheckVideoCodecH263()
{
	/****Codec No 0 represents H.263 *****/

	UpdateData(TRUE);

	if(m_bCheckH263)
		m_pVaxSIPUserAgent->SelectVideoCodec(VAX_CODEC_H263);

	else
		m_pVaxSIPUserAgent->DeselectVideoCodec(VAX_CODEC_H263);
}


void CSettingDlg::OnBnClickedCheckVideoCodecH263p()
{
	/****Codec No 1 represents H.263P *****/

	UpdateData(TRUE);

	if(m_bCheckH263P)
		m_pVaxSIPUserAgent->SelectVideoCodec(VAX_CODEC_H263P);

	else
		m_pVaxSIPUserAgent->DeselectVideoCodec(VAX_CODEC_H263P);
}

////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

void CSettingDlg::OnSelChangeComboVideoQuality()
{
	ActivateVideoQuality();
}

void CSettingDlg::ActivateVideoQuality()
{
	int nSelIndex = m_ctrlVideoQuality.GetCurSel();
	if(nSelIndex == -1) return;

	m_pVaxSIPUserAgent->SetVideoQuality(nSelIndex);
}

////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

void CSettingDlg::ActivateAudioCodecs()
{
	UpdateData();

	m_pVaxSIPUserAgent->DeselectAllVoiceCodec();
	
	if(m_bCheckG711U_LAW)
		m_pVaxSIPUserAgent->SelectVoiceCodec(VAX_CODEC_G711U);
	else
		m_pVaxSIPUserAgent->DeselectVoiceCodec(VAX_CODEC_G711U);
		

	if(m_bCheckG711A_LAW)
		m_pVaxSIPUserAgent->SelectVoiceCodec(VAX_CODEC_G711A);
	else
		m_pVaxSIPUserAgent->DeselectVoiceCodec(VAX_CODEC_G711A);


	if(m_bCheckGSM610)
		m_pVaxSIPUserAgent->SelectVoiceCodec(VAX_CODEC_GSM610);
	else
		m_pVaxSIPUserAgent->DeselectVoiceCodec(VAX_CODEC_GSM610);


	if(m_bCheckG729)
		m_pVaxSIPUserAgent->SelectVoiceCodec(VAX_CODEC_G729);
	else
		m_pVaxSIPUserAgent->DeselectVoiceCodec(VAX_CODEC_G729);


	if(m_bCheckILBC)
		m_pVaxSIPUserAgent->SelectVoiceCodec(VAX_CODEC_ILBC);
	else
		m_pVaxSIPUserAgent->DeselectVoiceCodec(VAX_CODEC_ILBC);
}

void CSettingDlg::ActivateVideoCodecs()
{
	UpdateData();

	m_pVaxSIPUserAgent->DeselectAllVideoCodec();

	if(m_bCheckH263)
		m_pVaxSIPUserAgent->SelectVideoCodec(VAX_CODEC_H263);

	if(m_bCheckH263P)
		m_pVaxSIPUserAgent->SelectVideoCodec(VAX_CODEC_H263P);
}

////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

void CSettingDlg::ActivateOtherSettings()
{
	UpdateData();

	if(m_bCheckEchoCancellation)
		m_pVaxSIPUserAgent->EnableEchoNoiseCancellation();
	else
		m_pVaxSIPUserAgent->DisableEchoNoiseCancellation();
	
	
	if(m_bCheckAGC)
        m_pVaxSIPUserAgent->EnableAGC(8000);
    else
        m_pVaxSIPUserAgent->DisableAGC();  


    if(m_bCheckMicBoost)
        m_pVaxSIPUserAgent->EnableMicBoost();
    else
       m_pVaxSIPUserAgent->DisableMicBoost();


    if(m_bCheckDontDisturb)
        m_pVaxSIPUserAgent->EnableDonotDisturb();
    else
        m_pVaxSIPUserAgent->DisableDonotDisturb();


    int nTotalLine = m_pVaxSIPUserAgent->GetTotalLine();

    for(int nLineCount = 0; nLineCount < nTotalLine; nLineCount++)
    {
		if(m_bCheckForceInbandDTMF)
            m_pVaxSIPUserAgent->EnableForceInbandDTMF(nLineCount);
        else
            m_pVaxSIPUserAgent->DisableForceInbandDTMF(nLineCount);
    }
}

////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

void CSettingDlg::ActivateVoiceChanger()
{
	UpdateData();

	switch(m_nRadioVCSelIndex)
	{
		case 0:
			m_pVaxSIPUserAgent->VoiceChanger(-1);
		break;

		case 1:
			m_pVaxSIPUserAgent->VoiceChanger(4);
		break;

		case 2:
			m_pVaxSIPUserAgent->VoiceChanger(8);
		break;

		case 3:
			m_pVaxSIPUserAgent->VoiceChanger(12);
		break;

		case 4:
			m_pVaxSIPUserAgent->VoiceChanger(16);
		break;

		case 5:
			m_pVaxSIPUserAgent->VoiceChanger(20);
		break;
	}

}

////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

void CSettingDlg::ActivateQoS()
{
	int nSelIndex = m_ctrlCallQoS.GetCurSel();
	
	if(nSelIndex != -1)
	{
		int nQoS = m_ctrlCallQoS.GetItemData(nSelIndex);

		if (nQoS == -1)
            m_pVaxSIPUserAgent->DeactivateQosSIP();
        else
            m_pVaxSIPUserAgent->ActivateQosSIP(nQoS);
	}

	nSelIndex = m_ctrlMediaQoS.GetCurSel();
	
	if(nSelIndex != -1)
	{
		int nQoS = m_ctrlMediaQoS.GetItemData(nSelIndex);

		if (nQoS == -1)
            m_pVaxSIPUserAgent->DeactivateQosRTP();
        else
            m_pVaxSIPUserAgent->ActivateQosRTP(nQoS);
	}
}

void CSettingDlg::OnCbnSelchangeComboCallQos()
{
	ActivateQoS();
}

void CSettingDlg::OnCbnSelchangeComboMediaQos()
{
	ActivateQoS();
}

////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

void CSettingDlg::ActivateEncryptionTunnel()
{
	UpdateData();

	if(m_sCryptTunnelIP.IsEmpty())
		return;

	m_pVaxSIPUserAgent->CryptCOMM(m_bCryptTunnelEnable, m_sCryptTunnelIP, m_nCryptTunnelPort);
}

void CSettingDlg::OnBnClickedCheckTunnelEnable()
{
	ActivateEncryptionTunnel();
}
